//===接口域名=== **url中不能有端口**
//const root = 'http://192.168.1.84:8008';
const root = 'https://wxapp.aimeifa.com';
//const root = 'http://localhost:2582';
var app=getApp(); 
if(!app){
  setTimeout(function(){
    app=getApp();
  })
}
var cookieStr;
// ==get请求方法模版
const GET = (url, callback) => {
  wx.request({
    url: root + url,
    header: { 'content-type': 'application/json', cookie:cookieStr },
    success(res) {
      if (res.data.code == 10000) {
        app.globalData.userInfo = null;
        cookieStr = '';
        app.getUserall(function () {
          GET(url, callback);
        });
        return;
      }
      callback(null, res.data)
    },
    fail(e) {
      console.error(e)
      callback(e)
    },

  })
}
// ==post请求方法模版
const POST = (url, data, callback) => {
  wx.request({
    method: 'POST',
    url: root + url,
    data: data,
    header: { 'content-type': 'application/x-www-form-urlencoded', cookie: cookieStr },
    success(res) {
      if(res.data.code==10000){
        app.globalData.userInfo=null;
        cookieStr='';
        app.getUserall(function(){
          POST(url, data, callback);
        });
        return;
      }
      callback(null, res.data)
    },
    fail(e) {
      console.error(e)
      callback(e)
    },

  })
}
const setCookie=(cookie)=>{
  cookieStr = cookie;
}


module.exports = {
  POST: POST,
  GET: GET, 
  setCookie: setCookie,
  root: root
} 